--- title: "46. Permutations" created: 2025-12-16 --- # 46. Permutations ## 题目 [**46. Permutations**](https://leetcode.com/problems/permutations/) ![[image-08f244d8.png]] ## 思路分析 c++中有全排列函数`next_permutation` java没有 只能用dfs写 ## 代码实现 ```java class Solution { List> res = new ArrayList<>(); List path = new ArrayList<>(); boolean[] st; public List> permute(int[] nums) { int n = nums.length; st = new boolean[n]; dfs(nums,0); return res; } void dfs(int[] nums,int u){ if(u==nums.length){ res.add(new ArrayList<>(path)); return; } for(int i=0;i